package com.android.dfsc;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;

public class DfscActivity extends Activity {
	protected static final int PROCESS_DIALOG = 0;
	protected static final int ALERT_SUCCESSFUL_DIALOG = 1;
	protected static final int ALERT_FAIL_DIALOG = 2;

	private int successfulFlag = 0;

	@Override
	protected Dialog onCreateDialog(int id) {
		AlertDialog resultDialog;
		switch (id) {
		case PROCESS_DIALOG:
			ProgressDialog processDialog = new ProgressDialog(this);
			processDialog.setMessage(getString(R.string.processing));
			processDialog.setIndeterminate(true);
			return processDialog;
		case ALERT_SUCCESSFUL_DIALOG:
			resultDialog = new AlertDialog.Builder(this).setTitle(
					getString(R.string.action)).create();

			resultDialog.setMessage(getString(R.string.successful));

			resultDialog.setButton(getText(R.string.ok),
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// finish();
						}
					});
			return resultDialog;
		case ALERT_FAIL_DIALOG:
			resultDialog = new AlertDialog.Builder(this).setTitle(
					getString(R.string.action)).create();

			resultDialog.setMessage(getString(R.string.fail));

			resultDialog.setButton(getText(R.string.ok),
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// finish();
						}
					});
			return resultDialog;
		}
		return null;
	}

	protected final BroadcastReceiver processCmdReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {

			unregisterReceiver(this);
			dismissDialog(PROCESS_DIALOG);

			if ((Integer) (intent.getExtras().get("result")) != successfulFlag) {
				showDialog(ALERT_FAIL_DIALOG);
			} else
				showDialog(ALERT_SUCCESSFUL_DIALOG);

		}
	};

	public int getSuccessfulFlag() {
		return successfulFlag;
	}

	public void setSuccessfulFlag(int successfulFlag) {
		this.successfulFlag = successfulFlag;
	}

	
}
